package hasthi.metamodel.resource;

import hasthi.common.HasthiException;
import hasthi.common.constants.HasthiConstants;
import hasthi.common.constants.WSDMConstants;
import hasthi.common.constants.WSDMConstants.SystemState;
import hasthi.manager.ManagedResourceType;
import hasthi.metamodel.ResourceUtils;

import java.util.Collection;

import javax.xml.namespace.QName;

public class Host implements EditableManagedResource {
    public static QName CPU_USAGE_PARAM = new QName(WSDMConstants.EXTREME_MANAGEMENT_NS,"cpuUsage");
    public static QName NUMBER_OF_SERVICES_PARAM = new QName(WSDMConstants.EXTREME_MANAGEMENT_NS,"numberOfServices");
    public static QName HARD_DISK_USAGE = new QName(WSDMConstants.EXTREME_MANAGEMENT_NS,"harddiskUsage");
    public static final QName WAN_MOUNT_PARAM = new QName(WSDMConstants.EXTREME_MANAGEMENT_NS,
        "WanMountHealth");
    private int serviceCount;
    
    public Host(){}
    
    private EditableManagedResource rawResource;
    
    Host(EditableManagedResource rowResource) {
        this.rawResource = rowResource;
    }

    public String getCategory() {
        return rawResource.getCategory();
    }

    public long getLastUpdated() {
        return rawResource.getLastUpdated();
    }

    public String getManagerAgentURL() {
        return rawResource.getManagerAgentURL();
    }

    public String getName() {
        return rawResource.getName();
    }

    public Collection<String> getProperties() {
        return rawResource.getProperties();
    }

    public String getProperty(String name) throws HasthiException {
        return rawResource.getProperty(name);
    }

    public QName getQName() {
        return rawResource.getQName();
    }

    public String getState() throws HasthiException {
        return rawResource.getState();
    }

    public String getType() {
        return rawResource.getType();
    }

    public ManagedResourceType toXml(boolean summerized) throws HasthiException {
        return rawResource.toXml(summerized);
    }
    
    public int getCpuUsage() throws HasthiException{
        return ResourceUtils.getIntProperty(rawResource, CPU_USAGE_PARAM.getLocalPart());
    }
    
    public int getNumberOfServices() throws HasthiException{
        return ResourceUtils.getIntProperty(rawResource, NUMBER_OF_SERVICES_PARAM.getLocalPart());
    }
    
    public int getHarddiskUsage() throws HasthiException{
        return ResourceUtils.getIntProperty(rawResource, HARD_DISK_USAGE.getLocalPart());
    }

    public void setLastUpdated(long lastUpdated) {
        rawResource.setLastUpdated(lastUpdated);
    }
    
    
    public String getWANMountHealth() throws HasthiException{
        String value = rawResource.getProperty(WAN_MOUNT_PARAM.getLocalPart());
        return (value == null)?HasthiConstants.UNKONWN_VALUE:value;
    } 

    public void setProperty(String name, Object value) throws HasthiException {
        rawResource.setProperty(name, value);
    }

    public void setState(SystemState state) throws HasthiException {
        rawResource.setState(state);
    }
    public int getServiceCount() {
        return serviceCount;
    }

    public void setServiceCount(int serviceCount) {
        this.serviceCount = serviceCount;
    }

    public String getGroup()throws HasthiException {
        return rawResource.getGroup();
    }

    public boolean isActive() {
        return rawResource.isActive();
    }

    public void setActive(boolean active) {
        this.rawResource.setActive(active);
    }
    
    @Override
    public boolean equals(Object obj) {
        return rawResource.equals(obj);
    }

    @Override
    public int hashCode() {
        return rawResource.hashCode();
    }
    
}
